//
//  TextVC.m
//  easyVideo-OC
//
//  Created by 李淼淼 on 2021/8/10.
//

#import "TextVC.h"

@interface TextVC ()
{
    UIButton *firstButton;
    UIButton *customButton;
    UIButton *thirdButton;
}
@end

@implementation TextVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createAButton];
    customButton = [self createACustomButton:CGRectMake(300, 200, 100, 100) action:@selector(buttonAction:) color:UIColor.blueColor titleText:@"第二个按钮"];
    [self.view addSubview:customButton];
    thirdButton = [self createACustomButton:CGRectMake(300, 400, 100, 100) action:@selector(buttonAction:) color:UIColor.brownColor titleText:@"第三个按钮"];
    [self.view addSubview:thirdButton];
}

//创建按钮
- (void)createAButton{
    firstButton = [UIButton buttonWithType:UIButtonTypeCustom];
    firstButton.frame = CGRectMake(100, 100, 100, 100);
    [firstButton setTitle:@"第一个按钮" forState:UIControlStateNormal];
    [firstButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    firstButton.backgroundColor = UIColor.redColor;
    [firstButton setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    [self.view addSubview:firstButton];
}
//创建一个自定义按钮
- (UIButton *)createACustomButton:(CGRect)rect action:(SEL)action color:(UIColor *)color titleText:(NSString *)title {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = rect;
    [button setTitle:title forState:UIControlStateNormal];
    [button addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
    button.backgroundColor = color;
    [button setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
    return button;
}
//添加按钮方法
-(void)buttonAction:(UIButton *)button{
    if (button == firstButton) {
        NSLog(@"点击了第一个按钮");
    }else if(button == customButton){
        NSLog(@"点击了第二个按钮");
    }else if(button == thirdButton){
        NSLog(@"点击了第三个按钮");
    }
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
